package com.cartoon.service.impl;

import com.cartoon.entity.User;
import com.cartoon.dao.UserDao;
import com.cartoon.service.UserService;
import com.cartoon.util.ResponseData;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (User)表服务实现类
 *
 * @author makejava
 * @since 2021-12-10 11:28:09
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public ResponseData insertIntoUserInfo(String userName, String headPicture) {
        try{
            userDao.insertIntoUserInfo(userName,headPicture);
            return new ResponseData("0","插入用户数据成功");
        }
        catch (Exception e){
            e.printStackTrace();
            System.out.println("用户名："+userName+"头像："+headPicture);
            return new ResponseData("9924","出错啦");
        }
    }

    @Override
    public ResponseData isExistUser(String userName,String password) {
        try{
            System.out.println("用户名是："+userDao.isExistUser(userName,password));
            return new ResponseData("0","查询数据库成功",userDao.isExistUser(userName,password));

        }
        catch (Exception e){
            e.printStackTrace();
            return new ResponseData("9924","查询用户是否存在失败");
        }
    }

    @Override
    public ResponseData getUserById(int userId) {
        try{
            return new ResponseData("0","查询成功",userDao.getUserById(userId));
        }
        catch (Exception e){
            e.printStackTrace();
            return new ResponseData("9924","查询失败");
        }
    }
}
